Given a string s
, return true
if it is possible to split the strings
into three non-empty palindromic substrings. Otherwise, returnfalse
.
A string is said to be palindrome if it the same string when reversed.
Input: s = "abcbdd" Output: true Explanation: "abcbdd" = "a" + "bcb" + "dd", and all three substrings are palindromes.
Input: s = "bcbddxy" Output: false Explanation: s cannot be split into 3 palindromes.
3 <= s.length <= 2000
s
consists only of lowercase English letters.
implSolution{pubfncheck_partitioning(s:String) -> bool{let s = s.as_bytes();letmut is_palindrome = vec![vec![false; s.len()]; s.len()];for r in0..s.len(){for l in0..=r { is_palindrome[l][r] = s[l] == s[r];if is_palindrome[l][r] && l + 2 < r { is_palindrome[l][r] = is_palindrome[l + 1][r - 1];}}}for l in1..s.len() - 1{for r in l..s.len() - 1{if is_palindrome[0][l - 1] && is_palindrome[l][r] && is_palindrome[r + 1][s.len() - 1]{returntrue;}}}false}}